package UIFree.behavior
{
	import UIFree.uif_transition;
	
	import flash.display.DisplayObject;
	import flash.filters.BlurFilter;

	public class bh_turning extends bh_stateBehavior {
		public function bh_turning(a_component:DisplayObject, a_options:Object) {
			super(a_component, a_options);
		}
	
		override protected function defaultOptions(): Object {
			return {
				distanceY	: component.height,
				distanceX	: 0,
				blurY		: 10,
				blurX		: 0,
				blurFilter 	: new BlurFilter(0, 0, 2),
				transition	: uif_transition.easeInOut(uif_transition.Default, 3),
				duration	: 500
			};
		}
		
		override protected function updateState(a_state: Number): void {
			if (a_state < 0) {
				component.y = getValue('y') + options.distanceY * (1 + a_state);
				component.x = getValue('x') + options.distanceX * (1 + a_state);
			} else {
				component.y = getValue('y') - options.distanceY * (1 - a_state);
				component.x = getValue('x') - options.distanceX * (1 - a_state);
			}
			
			options.blurFilter.blurY = options.blurY * Math.sin((a_state + 1) * Math.PI / 2);
			options.blurFilter.blurX = options.blurX * Math.sin((a_state + 1) * Math.PI / 2);
			component.filters = [options.blurFilter];
		}
		
		override protected function saveState(): void {
			pushValue('y', component.y);
			pushValue('x', component.x);
			pushValue('filters', component.filters);
		}
		
		override protected function restoreState(): void {
			component.filters 	= getValue('filters');
			component.y 		= getValue('y');
			component.x 		= getValue('x');
		}

		override protected function afterEnd(): void {
			restoreState();
			blurFilter = null;
			super.afterEnd();
		}
	}
}